<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$this->model('model')->up_cang();
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$tip='
	每仓建窖总积分[不含收益部分复投积分]产生总收益达到（**%）时，自动启动下一仓'.$this->y_title.'，以此类推；具体设置--移步--基本设置
	</br>1、点击启用建仓活动后，会自动建仓，无需手机建仓！
	';
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 15;
	}
	$total='';
	$parameter=array(
		'params'=>$params,
		'fields'=>$fields,
		'limit'=>array($pindex,$psize),
	);
	$list=pdo_getslice('jy_jicai_cang',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']=custom_url('jy_jicai/detail//id='.$item['id'],true);
			$item=$this->model('model')->up_canginfo($item);
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'建仓列表'),
			array('op'=>'open','title'=>'启用/关闭建仓'),
		),
		'list'=>array('data'=>'list','tip'=>$tip,'del_one'=>true,'delall'=>false,'edit'=>false,'list'=>array(
			array('type'=>'string','title'=>'ID','name'=>'id'),
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('type'=>'unitstring','unit'=>'窖','title'=>'共计建设（N）窖','name'=>'jian_num'),
			array('type'=>'unitstring','unit'=>'个','title'=>'第1窖建设总积分','name'=>'jian_jinum'),
			array('type'=>'unitstring','unit'=>'%','title'=>'每+1窖积分递增百分比（N%）','name'=>'jian_jinrate'),
			array('type'=>'unitstring','unit'=>'%','title'=>'建设收益','name'=>'jian_getrate'),
			array('name'=>'url','title'=>'链接','type'=>'copy'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'cang_status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'post','op'=>'up_sifang','title'=>'手动平仓','show'=>array('status'=>array(2,3))),
			array('type'=>'href','action'=>'/yaolist/','title'=>'窖列表'),
			array('type'=>'href','action'=>'/cangjifen/','title'=>'积分明细'),
			array('type'=>'href','action'=>'/cangjilog/','title'=>'收益明细'),
		),'batch'=>array(
			array('type'=>'post','url'=>'jy_jicai/list/jiancang/','msg'=>'确定要手动开启一仓？','title'=>'手动建仓'),
		)),
	);
	$return['cang_status']=$this->cang_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='open'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$this->plugin_setting('basic',$postdata);
		exi('操作成功！');
	}
	$return['item']=$this->plugin_setting('basic');
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$htmls=array(
		'type'=>'edit',
		'title'=>'开启关闭建仓活动',
		'edit'=>array(
				array('type'=>'tip','title'=>'[<red>温馨提示</red>]：启用建仓活动后，会自动建仓，无需手机建仓！！关闭建仓活动后，不会自动建仓，但是已经建好的仓，是无法停止的！'),
				array('type'=>'radio','title'=>'开启建仓活动？','name'=>'open_cang','options'=>'status'),		
			)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op'] == 'up_sifang'){
	$id=intval($_RQ['id']);
	$cang=pdo_get('jy_jicai_cang',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$this->model('model')->up_sifang($cang);
	exi('释放成功！');
}
if($_RQ['op'] == 'jiancang'){
	$paixu=pdo_count('jy_jicai_cang',array('uniacid'=>$_SESSION['uniacid']));
	$data=array(
						'uniacid'=>$_SESSION['uniacid'],
						'allget_rate'=>$this->setting['allget_rate']?:30,
						'jian_num'=>$this->setting['jian_num']?:3,
						'jian_jinum'=>$this->setting['jian_jinum']?:3000,
						'jian_jinrate'=>$this->setting['jian_jinrate']?:33,
						'jian_jinmin'=>$this->setting['jian_jinmin']?:1,
						'jian_jinmax'=>$this->setting['jian_jinmax']?:100,
						'jian_upjinmax'=>$this->setting['jian_upjinmax']?:100,
						'jian_cannum'=>$this->setting['jian_cannum']?:3,
						'jian_getrate'=>$this->setting['jian_getrate']?:10,
						'jian_tonum'=>$this->setting['jian_tonum']?:2,
						'jian_tobi'=>$this->setting['jian_tobi']?:50,
						'jian_tofee'=>$this->setting['jian_tofee']?:50,
						'paixu'=>$paixu+1,
						'createtime'=>TIMESTAMP,
						'status'=>0,
	);
	$this->insert('cang',$data);
	exi('手动建仓成功！');
}
if($_RQ['op'] == 'del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_jicai_cang',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		pdo_delete('jy_jicai_yao',array('cangid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_jicai_cang',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
				pdo_delete('jy_jicai_yao',array('cangid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}

?>